package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfwV2.dto.vo.HouseholdRegistrationInfoVO;
import com.budwk.app.sqfwV2.dto.vo.PersonInfoVO;
import com.budwk.app.sqfwV2.enums.povertyMonitoring.QuarterEnum;
import com.budwk.app.sqfwV2.service.povertyMonitoring.HouseholdRegistrationInfoService;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;
import org.nutz.mvc.upload.TempFile;
import org.nutz.mvc.upload.UploadAdaptor;

/**
 * @author zhangp
 * @description 户口基础信息
 * @className HouseholdRegistrationInfoController
 * @Date 11:29 2024/6/16
 */
@IocBean
@At("/platform/sqfwV2/householdRegistrationInfo")
@SLog(tag = "户口基础信息")
@ApiDefinition(tag = "户口基础信息")
@Slf4j
public class HouseholdRegistrationInfoController {

    @Inject
    private HouseholdRegistrationInfoService householdRegistrationInfoService;


    /**
     * 根据当前登录人获取场所
     *
     * @return
     */
    @At("/getHouseholdRegistrationInfoPage")
    @Ok("json")
    @POST
    @SaCheckLogin
    @SLog(tag = "户口列表查询", value = "${args[0]}")
    @ApiOperation(description = "分页查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "createdAt", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = HouseholdRegistrationInfoVO.class
    )
    @ApiResponses(implementation = HouseholdRegistrationInfoVO.class)
    public Result<?> getHouseholdRegistrationInfoPage(@Param("..") HouseholdRegistrationInfoVO householdRegistrationInfoDTO) {
        log.info("HouseholdRegistrationInfoController.HouseholdRegistrationInfoDTO 请求参数：householdRegistrationInfoDTO：{}", JSONObject.toJSONString(householdRegistrationInfoDTO));
        return householdRegistrationInfoService.getHouseholdRegistrationInfoPage(householdRegistrationInfoDTO);
    }


    /**
     * 根据当前登录人获取场所
     *
     * @return
     */
    @At("/getFamilyMembers")
    @Ok("json")
    @GET
    @SaCheckLogin
    @SLog(tag = "家庭人员列表", value = "${args[0]}")
    @ApiOperation(description = "家庭成员")
    @ApiFormParams(
            @ApiFormParam(name = "householdId", example = "1", description = "户id", type = "String")
    )
    @ApiResponses(implementation = PersonInfoVO.class)
    public Result<?> getFamilyMembers(@Param("householdId") String householdId) {
        log.info("HouseholdRegistrationInfoController.getFamilyMembers 请求参数：householdId：{}", householdId);
        return householdRegistrationInfoService.getFamilyMembers(householdId);
    }

    /**
     * 根据当前登录人获取场所
     *
     * @return
     */
    @At("/getQuarterList")
    @Ok("json")
    @GET
    @SaCheckLogin
    @SLog(tag = "获取季度", value = "")
    @ApiOperation(description = "获取季度")
    public Result<?> getQuarterList() {
        return Result.data(QuarterEnum.getQuarterList());
    }


    @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
    @At()
    @Ok("json")
    @POST
    @ApiOperation(name = "导入人员信息")
    @ApiFormParams(
            value = {@ApiFormParam(name = "file", description = "文件对象名")},
            mediaType = "multipart/form-data"
    )
    @SaCheckLogin
    public Result<?> importHouseholdPersonData(@Param("file") TempFile file) {
        return householdRegistrationInfoService.importHouseholdPersonData(file);
    }


}
